<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>socket</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.js"></script>
  </head>
  <body>
    <h3>socket.io的多房间1111</h3>
    <input type="button" value="加入购物车" onclick="addCart()" /><br />
    <script type="text/javascript">
      //和服务器建立长连接
      var socket = io.connect('http://localhost:5000?roomid=1');

      //接收服务器返回的信息
      socket.on('addCart', function (data) {
        console.log(data);
      });

      function addCart() {
        socket.emit('addCart', 'addCart');
      }
    </script>
  </body>
</html>
